using HCore.IOC.Beans.Factory.Attribute.Attr;
using HCore.IOC.Context.Event.Attr;
using HCore.IOC.Context.Stereotype;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.Support.CommandQuery;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.System.GunSystem;
using HCore.Unity.Core;

namespace HCore.Tests.Runtime.ShootingEditor2D.Scripts.Command
{
    public class ShiftGunCommand : ICommand
    {
    }

    [Component]
    public class ShiftGunCommandHandler
    {
        [Autowired] private IGunSystem mGunSystem;

        [EventListener]
        public void ExecuteCommand(ShiftGunCommand command)
        {
            // 不能切枪
            if (!mGunSystem.CanShiftGun) return;

            var currentGun = mGunSystem.CurrentGun;
            // 非闲置状态，不能切枪
            if (currentGun.GunState.Value != GunState.Idle) return;

            currentGun.GunState.Value = GunState.Shift;
            FunctionTimer.Create(() =>
            {
                currentGun.GunState.Value = GunState.Idle;
                mGunSystem.ShiftGun();
            }, mGunSystem.CurrentGunConfigItem.ShiftSeconds);
        }
    }
}